package net.maku.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import net.maku.bean.param.LoginUserParam;
import net.maku.bean.query.WebUserQuery;
import net.maku.bean.vo.WebUserVO;
import net.maku.convert.WebUserConvert;
import net.maku.entity.WebUserEntity;
import net.maku.service.WebUserService;
import net.maku.utils.PageResult;
import net.maku.utils.Result;

import org.springdoc.core.annotations.ParameterObject;
import org.springframework.web.bind.annotation.*;

import jakarta.validation.Valid;
import java.util.List;

/**
* 用户信息表
*
* @author 阿沐 babamu@126.com
* @since 1.0.0 2024-09-02
*/
@RestController
@RequestMapping("maku/web_user")
@Tag(name="用户信息表")
@AllArgsConstructor
public class WebUserController {
    private final WebUserService webUserService;


    @GetMapping("page")
    @Operation(summary = "分页")
    //@PreAuthorize("hasAuthority('maku:web_user:page')")
    public Result<PageResult<WebUserVO>> page(@ParameterObject @Valid WebUserQuery query){
        PageResult<WebUserVO> page = webUserService.page(query);

        return Result.ok(page);
    }

    @GetMapping("{id}")
    @Operation(summary = "信息")
    //@PreAuthorize("hasAuthority('maku:web_user:info')")
    public Result<WebUserVO> get(@PathVariable("id") Long id){
        WebUserEntity entity = webUserService.getById(id);

        return Result.ok(WebUserConvert.INSTANCE.convert(entity));
    }

    @PostMapping
    @Operation(summary = "保存")
    //@PreAuthorize("hasAuthority('maku:web_user:save')")
    public Result<String> save(@RequestBody WebUserVO vo){
        webUserService.save(vo);

        return Result.ok();
    }

    @PutMapping
    @Operation(summary = "修改")
    //@PreAuthorize("hasAuthority('maku:web_user:update')")
    public Result<String> update(@RequestBody @Valid WebUserVO vo){
        webUserService.update(vo);

        return Result.ok();
    }

    @DeleteMapping
    @Operation(summary = "删除")
    //@PreAuthorize("hasAuthority('maku:web_user:delete')")
    public Result<String> delete(@RequestBody List<Long> idList){
        webUserService.delete(idList);

        return Result.ok();
    }
}